<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="include :: header('用户选择')" />
</head>
<body class="gray-bg">
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="user-form">
					<div class="select-list">
						<ul>
							<li>
								用户名称：<input type="text" name="username"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var prefix = ctx + "system/user";
		var userList = "";
        $(function() {
            var options = {
                url: prefix + "/list",
		        showSearch: false,
		        showRefresh: false,
		        showToggle: false,
		        showColumns: false,
				onLoadSuccess: onLoadSuccess,
                columns: [{
		            radio: true
		        },
				{
					field : 'id',
					title : '用户ID'
				},
				{
					field : 'username',
					title : '用户姓名'
				}]
            };
            $.table.init(options);
        });
        
        /* 添加用户-选择用户-提交 */
		function submitHandler() {
			var rows = $.table.selectFirstColumns();
			if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
			$.modal.close();
			// 父页面的变量
			userList.forEach(value => {
				if(value.id === rows.join()){
					parent.$('#userName').val(value.username);
					parent.$('input[name="toUserId"]').val(value.id);
				}
			})
		}
		function onLoadSuccess(res) {
			userList = res.rows;
		}
    </script>
</body>
</html>